<template>
	<view class="page">
		<view class="main">
		<!-- 	<view class="head flex">
				到微信账号 
				<view class="userData flex">
					<view class="img">
						<image :src="user.avatar" mode=""></image>
					</view>
					<text>{{user.userName}}</text>
				</view>
			</view> -->
			
			<!--  -->
			<view class="content">
				提现金额
				<view class="input flex">
					<text>￥</text>
					<input class="shuru" type="" v-model="txmoney"/>
				</view>
				<view class="tit">
					可提现金额： ￥{{Number(money).toFixed(2)}} <text @click="txMoney">全部提现</text>
				</view>
			</view>
			
			<view class="button" @click="Withdrawal">
				提现
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// user: [],
				money: '',
				txmoney: '',
			}
		},
		mounted(){
			// this.userMethod()
			this.moneyData()
		},
		
		// onShow(){
		// 	this.avatarUrl=uni.getStorageSync('avatarUrl')
		// 	this.nickName=uni.getStorageSync('nickName')
		// },
		
		methods: {
			txMoney(){
				this.txmoney = this.money
			},
			// 获取用户总数据
			// userMethod() {
			// 	const requestParam = {
			// 		url: "/api/account/getMyData/1",
			// 		method: "GET",
			// 		callBack: (res) => {
			// 			if(res.code == 200){
			// 				this.user = res.data
			// 				console.log(this.user)
			// 			}else{
			// 				uni.showToast({
			// 					title: res.msg,
			// 					icon: "none",
			// 				})
			// 			}
			// 		}
			// 	}
			// 	this.$http.request(requestParam);
			// },
			//用户余额
			moneyData(){
				const requestMoney = {
					url: '/api/account/accountMoney',
					method: "post",
					callBack: (res) => {
						this.money = JSON.stringify(res.data.sumMoney-res.data.redMoney)
					}
				}
				this.$http.request(requestMoney)
			},
			
			
			// 提现 
			Withdrawal(){
				console.log(this.txmoney)
				console.log(this.money)
				if(!this.txmoney){
					uni.showToast({
						title: '金额不能为空',
						icon: "none",
					})
					return
				}
				if(this.txmoney > this.money){
					uni.showToast({
						title: '主人，你还没有那么多钱呢！',
						icon: "none",
					})
					return
				}
				if(this.money == 0){
					uni.showToast({
						title: '主人，你没有可提现的钱呢！',
						icon: "none",
					})
					return
				}
				const requestParam = {
					url: "/api/account/embody",
					method: "POST",
					data:{
						content: this.txmoney
					},
					callBack: (res) => {
						if(res.code == 200){
							if(res.data.sate == 2){
								uni.showToast({
									title: '提现金额大于余额',
									icon: "none",
								})
								return
							}
							if(res.data.sate == 0){
								uni.showToast({
									title: '提现金额不正确，或不为整数',
									icon: "none",
								})
								return
							}
							if(res.data.sate == 1){
								this.moneyData()
								uni.showToast({
									title: '请联系在线客服',
									icon: "none",
								})
								return
							}
						}else{
							uni.showToast({
								title: res.msg,
								icon: "none",
							})
						}
					}
				}
				this.$http.request(requestParam);
				
			}
			
		}
	}
</script>

<style lang="scss">
	.flex{
		display: flex;
	}
	.page{
		padding: 20rpx;
		min-height: 100vh;
		background-color: #f1f1f1;
	}
	.main{
		background-color: #fff;
		border: 10rpx;
		padding: 20rpx 20rpx 40rpx 20rpx;
		border-radius: 10rpx;
	}
	.head{
		font-size: 28rpx;
		color: #333333;
		line-height: 100rpx;
		padding-bottom: 20rpx;
		border-bottom: 2rpx solid #eee;
		.userData{
			margin-left: 20rpx;
			.img>image{
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
			}
			.img{
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
				background-color: #EEEEEE;
				margin-right: 20rpx;
			}
		}
	}
	.content{
		padding-top: 20rpx;
		font-size: 28rpx;
		color: #333333;
		.input{
			padding-bottom: 30rpx;
			border-bottom: 2rpx solid #eee;
			>text{
				font-size: 2rem;
			}
			.shuru{
				line-height: 60rpx;
				margin-top: 25rpx;
				font-size: 30rpx;
			}
		}
		.tit{
			font-size: 24rpx;
			margin-top: 20rpx;
			>text{
				color: #FFC300;
				margin-left: 20rpx;
			}
		}
		
	}
	.button{
		border-radius: 20rpx;
		text-align: center;
		line-height: 80rpx;
		font-size: 30rpx;
		background-color: #FFC300;
		margin-top: 40rpx;
		color: #fff;
	}

</style>
